require(['../config'], () => {
	require(['swiper', 'template', 'jcookie', 'bootstrap', 'jquery', 'Header', 'footer'], (swiper, template, jcookie) => {
		class register {
			constructor() {
				this.into()
				
			}

			into() {
				$('.register-btn').on('click', () => {
					const name = $('#xing').val() + $('#ming').val()
					const pwd = $('#pwd').val()
					const phone = $('#phone-num').val()
					
					var res = [{
						name: name,
						pwd: pwd,
						phone: phone,
					}]
					
					if($('#xing').val() === ''){
						alert('请输入完整信息')
					}else if($('#ming').val() === ''){
						alert('请输入完整信息')
					}else if($('#pwd').val() === ''){
						alert('请输入完整信息')
					}else if($('#phone-num').val() === ''){
						alert('请输入完整信息')
					}else{
						this.isName(name,pwd,phone)
					}
				})
			}
			isName(name,pwd,phone){
				var res = {
					name: name,
					pwd: pwd,
					phone: phone,
				}
				
				let ff = localStorage.getItem('ff')
				if (ff) {
					ff = JSON.parse(ff)
					const isExist = ff.every((shop) => {
						return shop.name === name;
						shop.pwd === pwd;
						shop.phone === phone;
					})
					console.log(isExist)
					if (isExist) {
						alert('该用户已注册')
					} else {
						ff.push(res)
						localStorage.setItem('ff', JSON.stringify(ff))
						$('#xing').val('')
						$('#ming').val('')
						$('#xing').val('')
						$('#ming').val('')
						$('#phone-num').val('')
						alert('注册成功，去登录吧!')
						location.href="/html/modules/login.html"
					}
				} else {
					localStorage.setItem('ff', JSON.stringify([res]))
					$('#xing').val('')
					$('#ming').val('')
					$('#xing').val('')
					$('#ming').val('')
					$('#phone-num').val('')
					alert('注册成功，去登录吧!')
					location.href="/html/modules/login.html"
				}
			}
			
		}
		new register()
	})
})
